﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TypeTree.aspx.cs" Inherits="ZLCMS.Web.SystemManage.Basics.TypeTree.TypeTree" %>

<form id="pageForm" method="post" runat="Server" class="pageForm" 
    onsubmit="return navTabSearch(this);" action="/SystemManage/Basics/TypeTree/TypeTree.aspx?search=1">
    
<div class="pageContent">
	<div class="pageFormContent" minH="450" layoutH="30">
	
    <h2 class="contentTitle">提示:请使用右键菜单管理分类</h2>
    
		<div id="treepannel">
            <ul id="<%=Guid.NewGuid().ToString() %>" class="ztree"  setting='
{
	view: {
		addHoverDom: addHoverDom,
		removeHoverDom: removeHoverDom,
		selectedMulti: false
	},
    data: {
		key: {
			name: "Name"
		},
		simpleData: {
			enable: true,
			idKey: "Id",
			pIdKey: "ParentId"
		},
		keep: {
			parent: false,
			leaf: false
		}
	},
	async: {
		enable: true,
		type: "post",
		url: "/SystemManage/Control/ddt/TreeData.aspx?Kind=<%=Request["Kind"] %>",
        otherParam: ["temp", new Date().valueOf()]
	},
    edit: {
		enable: true,
		editNameSelectAll: false,
		showRemoveBtn: true,
		showRenameBtn: true,
		removeTitle: "删除",
		renameTitle: "修改"
	},
	callback: {
		beforeDrag: function (treeId, treeNodes) {
			return false;
		},
        onAsyncSuccess:function(event, treeId, treeNode, msg){
            $.fn.zTree.getZTreeObj(treeId).expandAll(true);
        },
        //编辑
        beforeRename: function(treeId, treeNode, newName, isCancel){
            var node=new Object();
            node.Name=newName;
            node.ParentId=treeNode.ParentId;
            node.Id=treeNode.Id;
            node.temp=new Date().valueOf();
            var json = $.toJSON(node);
            $.get("/SystemManage/Basics/TypeTree/TypeTree.aspx",{opt:"edit", node:json } , function(data){
                var obj=$.parseJSON(data);
                treeNode.ItemText = obj.Name;
                $.fn.zTree.getZTreeObj(treeId).updateNode(treeNode);
                alertMsg.correct("操作成功");
            });
            return true;
        },
        //删除
        beforeRemove:function(treeId, treeNode){
            alertMsg.confirm("请确认删除当前菜单项", {
                okCall: function() {alert("dd");
                    var node=new Object();
                    node.Id=treeNode.Id;
                    node.temp=new Date().valueOf();
                    var json = $.toJSON(node);
              
                    $.get("/SystemManage/Basics/TypeTree/TypeTree.aspx", {opt:"del", node:json}, function(data){
                        $.fn.zTree.getZTreeObj(treeId).removeChildNodes(treeNode);
                        $.fn.zTree.getZTreeObj(treeId).removeNode(treeNode);
                        alertMsg.correct("操作成功");
                    }); 
                }
            });
            return false;
        },
        onClick:function(event, treeId, treeNode, clickFlag){
           
        }
	}
}
'></ul>
        </div>
	</div>
	
</div>
</form>
<script type="text/javascript">
    //添加节点
    function addItem(treeId, Node) {
        var pid;

        if (Node) {
            pid = Node.ParentId;
        }
     
        var node = new Object();
        node.Name = "新的菜单";
        node.Id = Node.Id;
       
       //当为根节点添加子菜单时 pid==0
        if (pid == undefined) {
            pid = 0;
        } 
        node.ParentId = pid;

        node.temp = new Date().valueOf();
        var json = $.toJSON(node);

        $.get("/SystemManage/Basics/TypeTree/TypeTree.aspx", { opt: "add", node: json }, function (data) {
           
            var zTree = $.fn.zTree.getZTreeObj(treeId);
            if (Node) {
                zTree.addNodes(Node, $.parseJSON(data));
            } else {
                zTree.addNodes(null, $.parseJSON(data));
            }
        });
    }

    function addHoverDom(treeId, treeNode) {
        var sObj = $("#" + treeNode.tId + "_span");
        if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
        var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
				+ "' title='增加子菜单' onfocus='this.blur();'></span>";
        sObj.after(addStr);
        var btn = $("#addBtn_" + treeNode.tId);
        if (btn) btn.bind("click", function () {
            addItem(treeId, treeNode);
            return false;
        });
    };
    function removeHoverDom(treeId, treeNode) {
        $("#addBtn_" + treeNode.tId).unbind().remove();
    };

</script>